package com.black.web.app.my.mydata;

import com.black.app.domain.my.*;
import com.black.app.domain.req.my.mydata.*;
import com.black.app.domain.resp.my.mydata.AppMyDataResp;
import com.black.app.service.my.*;
import com.black.common.core.controller.BaseController;
import com.black.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * ClassName: MyDataController
 * Package: com.black.app.controller.my.mydata
 * Description:
 *
 * @Author luo
 * @Create 2024/10/23 21:42
 * @Version 1.0
 */
@Api(tags = "app-我的数据Api")
@RestController
@RequestMapping(value = "/app/mydata")
public class MyDataController extends BaseController {

    @Autowired
    private AppMyDataService appMyDataService;

    @Autowired
    private AppMyWeightDetailService appMyWeightDetailService;

    @Autowired
    private AppMyHabitDetailService appMyHabitDetailService;

    @Autowired
    private AppMyDrinkDetailService appMyDrinkDetailService;

    @Autowired
    private AppMyHeatDetailService appMyHeatDetailService;

    @Autowired
    private AppMyMenstrualDetailService appMyMenstrualDetailService;

    @Autowired
    private AppMyMoveDetailService appMyMoveDetailService;

    // 腰围变化记录
    @Autowired
    private AppMyWaistlineDetailService appMyWaistlineDetailService;

    // 步数记录
    @Autowired
    private AppMyWalkDetailService appMyWalkDetailService;


    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "分页查询我的数据")
    @GetMapping(value = "/data")
    public R<PageInfo<AppMyDataResp>> list(AppMyDataQueryReq req) {
        PageInfo<AppMyDataResp> page = this.appMyDataService.paginationQuery(req);
        return R.ok(page);
    }

    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "体重记录新增")
    @PostMapping(value = "/addweight")
    public R addWeight(@RequestBody @Valid AppMyDataWeightDetailAddReq req) {
        boolean result = this.appMyWeightDetailService.add(req);
        // 如果添加成功则执行更新
        if (result){
            this.editWeight(req);
        }
        return super.isSuccess(result);
    }

    // 获取体重记录
    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "获取当前用户的体重详情记录")
    @GetMapping(value = "/getweight")
    public R<PageInfo<AppMyWeightDetail>> listGetWeight(AppMyDataWeightDetailAddReq req) {
        PageInfo<AppMyWeightDetail> page = this.appMyWeightDetailService.getWeight(req);
        return R.ok(page);
    }




    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "习惯记录新增")
    @PostMapping(value = "/addhabit")
    public R addHabit(@RequestBody @Valid AppMyDataHabitDetailAddReq req) {
        boolean result = this.appMyHabitDetailService.addHabit(req);
        if (result){
            this.editHabit(req);
        }
        return super.isSuccess(result);
    }

    // 获取习惯记录
    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "获取当前用户的习惯详情记录")
    @GetMapping(value = "/gethabit")
    public R<PageInfo<AppMyHabitDetail>> listGetHabit(AppMyDataHabitDetailAddReq req) {
        PageInfo<AppMyHabitDetail> page = this.appMyHabitDetailService.getHabit(req);
        return R.ok(page);
    }


    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "喝水记录新增")
    @PostMapping(value = "/adddrink")
    public R addDrink(@RequestBody @Valid AppMyDataDrinkDetailAddReq req) {
        boolean result = this.appMyDrinkDetailService.addDrink(req);
        if (result){
            this.editDrink(req);
        }
        return super.isSuccess(result);
    }

    // 获取喝水记录
    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "获取当前用户的喝水详情记录")
    @GetMapping(value = "/getdrink")
    public R<PageInfo<AppMyDrinkDetail>> listGetDrink(AppMyDataDrinkDetailAddReq req) {
        PageInfo<AppMyDrinkDetail> page = this.appMyDrinkDetailService.getDrink(req);
        return R.ok(page);
    }

    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "热量记录新增")
    @PostMapping(value = "/addcalorie")
    public R addCalorie(@RequestBody @Valid AppMyHeatDetailAddReq req) {
        boolean result = this.appMyHeatDetailService.addCalorie(req);
        if (result){
            this.editCalorie(req);
        }
        return super.isSuccess(result);
    }

    // 获取热量记录
    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "获取当前用户的热量详情记录")
    @GetMapping(value = "/getcalorie")
    public R<PageInfo<AppMyHeatDetail>> listGetCalorie(AppMyHeatDetailAddReq req) {
        PageInfo<AppMyHeatDetail> page = this.appMyHeatDetailService.getCalorie(req);
        return R.ok(page);
    }

    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "经期记录新增")
    @PostMapping(value = "/addperiod")
    public R addPeriod(@RequestBody @Valid AppMyMenstrualDetailAddReq req) {
        boolean result = this.appMyMenstrualDetailService.addMenstrual(req);
        if (result){
            this.editPeriod(req);
        }
        return super.isSuccess(result);
    }

    // 获取经期记录
    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "获取当前用户的经期详情记录")
    @GetMapping(value = "/getperiod")
    public R<PageInfo<AppMyMenstrualDetail>> listGetPeriod(AppMyMenstrualDetailAddReq req) {
        PageInfo<AppMyMenstrualDetail> page = this.appMyMenstrualDetailService.getMenstrual(req);
        return R.ok(page);
    }

    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "运动记录新增")
    @PostMapping(value = "/addmove")
    public R addMove(@RequestBody @Valid AppMyMoveDetailAddReq req) {
        boolean result = this.appMyMoveDetailService.addMove(req);
        if (result){
            this.editMove(req);
        }
        return super.isSuccess(result);
    }

    // 获取运动记录
    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "获取当前用户的运动详情记录")
    @GetMapping(value = "/getmove")
    public R<PageInfo<AppMyMoveDetail>> listGetMove(AppMyMoveDetailAddReq req) {
        PageInfo<AppMyMoveDetail> page = this.appMyMoveDetailService.getMove(req);
        return R.ok(page);
    }

    // 腰围新增
    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "新增腰围记录")
    @PostMapping(value = "/addwaistline")
    public R addWaist(@RequestBody @Valid AppMyWaistlineDetailAddReq req){
        boolean result = this.appMyWaistlineDetailService.addWaistline(req);
        if (result){
            this.editWaist(req);
        }
        return super.isSuccess(result);
    }

    // 获取腰围记录
    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "获取当前用户的腰围详情记录")
    @GetMapping(value = "/getwaist")
    public R<PageInfo<AppMyWaistlineDetail>> listGetWaist(AppMyWaistlineDetailAddReq req) {
        PageInfo<AppMyWaistlineDetail> page = this.appMyWaistlineDetailService.getWaistline(req);
        return R.ok(page);
    }

    // 步数新增
    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "新增步数记录")
    @PostMapping(value = "/addwalk")
    public R addStep(@RequestBody @Valid AppMyWalkDetailAddReq req){
        boolean result = this.appMyWalkDetailService.addStep(req);
        if (result){
            this.editStep(req);
        }
        return super.isSuccess(result);
    }

    // 获取步数记录
    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "获取当前用户的步数详情记录")
    @GetMapping(value = "/getwalk")
    public R<PageInfo<AppMyWalkDetail>> listGetWalk(AppMyWalkDetailAddReq req) {
        PageInfo<AppMyWalkDetail> page = this.appMyWalkDetailService.getWalk(req);
        return R.ok(page);
    }


    @PreAuthorize("@ss.hasAppPermi()")
    // 默认隐藏
    @ApiOperation(value = "根据体重记录详情表更新体重记录", hidden = true)
    @PutMapping(value = "/editweight")
    public R editWeight(@RequestBody @Valid AppMyDataWeightDetailAddReq req) {
        boolean result = this.appMyDataService.editWeight(req);
        return super.isSuccess(result);
    }

    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "根据习惯记录详情表更新习惯记录", hidden = true)
    @PutMapping(value = "/edithabit")
    public R editHabit(@RequestBody @Valid AppMyDataHabitDetailAddReq req) {
        boolean result = this.appMyDataService.editHabit(req);
        return super.isSuccess(result);
    }

    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "根据喝水记录详情更新喝水记录", hidden = true)
    @PutMapping(value = "/editdrink")
    public R editDrink(@RequestBody @Valid AppMyDataDrinkDetailAddReq req) {
        boolean result = this.appMyDataService.editDrink(req);
        return super.isSuccess(result);
    }


    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "根据热量记录详情更新热量记录", hidden = true)
    @PutMapping(value = "/editcalorie")
    public R editCalorie(@RequestBody @Valid AppMyHeatDetailAddReq req) {
        boolean result = this.appMyDataService.editCalorie(req);
        return super.isSuccess(result);
    }

    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "根据经期记录详情更新经期记录", hidden = true)
    @PutMapping(value = "/editperiod")
    public R editPeriod(@RequestBody @Valid AppMyMenstrualDetailAddReq req) {
        boolean result = this.appMyDataService.editMenstrual(req);
        return super.isSuccess(result);
    }

    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "根据运动记录详情更新运动记录", hidden = true)
    @PutMapping(value = "/editmove")
    public R editMove(@RequestBody @Valid AppMyMoveDetailAddReq req) {
        boolean result = this.appMyDataService.editMove(req);
        return super.isSuccess(result);
    }

    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "根据腰围记录详情更新腰围记录", hidden = true)
    @PutMapping(value = "/editwaist")
    public R editWaist(@RequestBody @Valid AppMyWaistlineDetailAddReq req) {
        boolean result = this.appMyDataService.editWaist(req);
        return super.isSuccess(result);
    }

    // 步数
    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "根据步数记录详情更新步数记录", hidden = true)
    @PutMapping(value = "/editwalk")
    public R editStep(@RequestBody @Valid AppMyWalkDetailAddReq req) {
        boolean result = this.appMyDataService.editStep(req);
        return super.isSuccess(result);
    }


}
